<template>
  <div class="row">
    <div class="col-md-12">
      <FrontSideTable
        v-show="currentView === REPORT_VIEW"
        ref="reportTable"
        dataUrl="/report/regular/getRegularReportList"
        tableTitle="定期检查报告批次列表"
        addUrl="/report/regular/add"
        deleteUrl="/report/regular/delete"
        searchHint="根据名称查找"
        :form="form"
        :rules="rules"
        :searchProps="searchProps"
        :columns="columns"
        @beforeAdd="beforeAdd"
        @onView="handleView">
        <!--表单-->
        <template slot="form">
          <el-form-item label="报告批次名称" prop="name">
            <el-input v-model="form.name" placeholder="输入名称"></el-input>
          </el-form-item>
          <el-form-item label="报告模板" prop="templateId">
            <el-select v-model="form.templateId" style="width: 100%;" placeholder="选择报告模板" filterable>
              <el-option v-for="item of templateList" :key="item.id" :label="item.name" :value="item.id"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="构件编号方向" prop="direction">
            <el-radio-group v-model="form.direction">
              <el-radio :label="0">从左往右</el-radio>
              <el-radio :label="1">从右往左</el-radio>
            </el-radio-group>
          </el-form-item>
        </template>

        <!--进度列-->
        <template slot="afterColumns">
          <el-table-column label="报告进度" align="center" width="170">
            <template slot-scope="scope">
              <ProgressIndicator :total="scope.row.total" :progress="scope.row.progress"></ProgressIndicator>
            </template>
          </el-table-column>
        </template>
      </FrontSideTable>

      <!--桥梁选择界面-->
      <RegularReportBridge v-if="currentView === BRIDGE_VIEW" :report="currentReport" @onBack="handleBack"></RegularReportBridge>
    </div>
  </div>
</template>

<script>
  import FrontSideTable from "../../template/FrontSideTable.vue"
  import ProgressIndicator from "../../template/ProgressIndicator"
  import RegularReportBridge from "../../template/RegularReportBridge.vue"
  import {clearFields} from "../../../assets/js/utils/ObjectUtils";
  import {doGet} from "../../../assets/js/utils/RequestUtils";

  const TEMPLATE_URL = "/report/regular/getTemplateList";

  const REPORT_VIEW = 0, BRIDGE_VIEW = 1;

  export default {
    name:"ReportRegularManagement",
    data() {
      return {
        currentView:REPORT_VIEW,
        currentReport:null,
        form:{direction: 0},
        rules:{
          name:[
            {required:true, message:"请输入报告批次名称", trigger:"blur"}
          ],
          templateId:[
            {required:true, message:"请选择报告模板", trigger:"blur"}
          ]
        },
        searchProps:["name", "templateName"],
        columns:[
          {prop:"name", label:"报告批次"},
          {prop:"templateName", label:"报告模板"},
          {prop:"directionName", label:"构件编号方向"},
          {prop:"deleteDate", label:"自动删除日期", sortable:"custom"}
        ],
        templateList:[],
        REPORT_VIEW,
        BRIDGE_VIEW
      }
    },
    methods: {
      beforeAdd() {
        clearFields(this.form);
        //设为定期检查
        this.form.direction = 0;
        this.form.type = 2;
      },
      fetchTemplateList() {
        doGet(TEMPLATE_URL, {component:this})
          .then(response=>this.templateList = response);
      },
      handleView(data) {
        this.currentReport=data;
        this.currentView = BRIDGE_VIEW;
      },
      handleBack() {
        this.currentView = REPORT_VIEW;
        if(this.$refs["reportTable"]) this.$refs["reportTable"].fetchData();
      }
    },
    mounted() {
      this.fetchTemplateList();
    },
    components:{FrontSideTable, ProgressIndicator, RegularReportBridge}
  }
</script>



// WEBPACK FOOTER //
// RegularReportManagement.vue?0878b6cc
